<template>
  <el-row :gutter="40" class="echarts-group">
    <el-col :xs="12" :sm="12" :lg="6" class="card-echarts-col">
      <div class="card-echarts" @click="handleSetLineChartData('newVisitis')">
        <div class="card-echarts-description">
          <div class="card-echarts-count">{{ device_data[0] }}</div>
          <div class="card-echarts-text">
            设备总数
          </div>
        </div>
      </div>
    </el-col>
    <el-col :xs="12" :sm="12" :lg="6" class="card-echarts-col">
      <div class="card-echarts" @click="handleSetLineChartData('messages')">
        <div class="card-echarts-description">
          <div class="card-echarts-count">{{ device_data[1] }}</div>
          <div class="card-echarts-text">
            分配总数
          </div>
        </div>
      </div>
    </el-col>
    <el-col :xs="12" :sm="12" :lg="6" class="card-echarts-col">
      <div class="card-echarts" @click="handleSetLineChartData('purchases')">
        <div class="card-echarts-description">
          <div class="card-echarts-text">
            CPU使用率
          </div>
        </div>
        <div class="cart-echarts-progress progress-cpu">
          <el-progress type="circle" :percentage="25" :stroke-width="13" color="#0e92fd" :width="185" />
          <!-- <div class="my-progress" id="myCanvas"></div> -->
        </div>
      </div>
    </el-col>
    <el-col :xs="12" :sm="12" :lg="6" class="card-echarts-col">
      <div class="card-echarts" @click="handleSetLineChartData('shoppings')">
        <div class="card-echarts-description">
          <div class="card-echarts-text">
            JVM内存
          </div>
        </div>
        <div class="cart-echarts-progress progress-jvm">
          <el-progress type="dashboard" :percentage="25" :stroke-width="13" color="#0e92fd" :width="185" />
          <!-- <div class="my-progress" id="myCanvas"></div> -->
        </div>
      </div>
    </el-col>
  </el-row>
</template>

<script>
import CountTo from 'vue-count-to'

export default {
  // name: 'EchartsGroup',
  components: {
    CountTo
  },
  props: {
    device_data: {
      type: Array,
      require: true // 数组长度length 必为4
    }
  },
  data() {
    return {
      img: {
        statistics0: 'url(' + require('../../../assets/img/statistics0.png') + ')',
        statistics1: 'url(' + require('../../../assets/img/statistics1.png') + ')',
        statistics2: 'url(' + require('../../../assets/img/statistics2.png') + ')',
        statistics3: 'url(' + require('../../../assets/img/statistics3.png') + ')'
      }
      // circle_data: [
      //   {bgcolor:'yellowgreen',value:30},
      //   {bgcolor:'green',value:30},
      //   {bgcolor:'yellow',value:40}
      // ],
      // circle_canvas_cpu: document.getElementById("myCanvas"),
      // circle_ctx: canvas.getContext("2d"),
    }
  },
  mounted() {
    // this.drawCircle(this.circle_ctx, this.circle_data, {cood:{x:200,y:200},radius:150})
  },
  methods: {
    handleSetLineChartData(type) {
      this.$emit('handleSetLineChartData', type) // 向外触发,, 影响第二行 折线图展示哪一个数据
    }
    // 圆环
    // drawCircle(ctx,data,option){
    //   var cood=option.cood;
    //   var radius=option.radius;
    //   var lastpos=pos=0;
    //   for(var i=0;i<data.length;i++){
    //     ctx.beginPath();
    //     ctx.moveTo(cood.x,cood.y);
    //     ctx.fillStyle = data[i].bgcolor;
    //     pos=lastpos+Math.PI*2*data[i].value/100;
    //     ctx.arc(cood.x,cood.y,radius,lastpos,pos,false);
    //     ctx.fill();
    //     lastpos=pos;
    //   }
    //   ctx.beginPath();
    //   ctx.fillStyle ="white";
    //   radius*=0.5;
    //   ctx.arc(cood.x,cood.y,radius,0,Math.PI*2 ,false);
    //   ctx.fill();
    // }
  }
}
</script>

<style lang="scss">
  .progress-cpu .el-progress-circle {
    transform: rotateZ(-90deg);
  }
</style>

<style lang="scss" scoped>
.echarts-group {
  // margin-top: 18px;

  .card-echarts-col {
    margin-bottom: 32px;
  }

  .card-echarts {
    height: 240px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    background: #fff;
    padding: 5px 10px 5px 20px;
    box-shadow: 4px 4px 40px rgba(0, 0, 0, .05);
    border-color: rgba(0, 0, 0, .05);
    border-radius: 8px;
    .card-echarts-description {
      // background-color: aqua;
      float: left;
      font-weight: bold;
      .card-echarts-text {
        position: absolute;
        font-size: 18px;
      }
      .card-echarts-count {
        font-size: 22px;
      }
    }
    .cart-echarts-progress {
      width:185px;
      height: 185px;
      border-radius: 50%;
      margin: 45px auto;
      // background-color: bisque;
      display: flex;
      justify-content: center;
      align-items: center;
    }
  }
}

@media (max-width:550px) {
  .card-echarts-description {
    display: none;
  }

  .card-echarts-icon-wrapper {
    float: none !important;
    width: 100%;
    height: 100%;
    margin: 0 !important;

    .svg-icon {
      display: block;
      margin: 14px auto !important;
      float: none !important;
    }
  }
}
</style>
